package customExercise;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author:Clarence
 * @date 2022/2/23 14:40
 * @motto Practice is the sole criterion for testing truth.
 */
/**
 * CAS是什么？ compareAndSet
 * */
public class CasDemo {
    public static void main(String[] args) {
        //原子操作
        AtomicInteger atomicInteger = new AtomicInteger(5);
        //期望值为5，若和5相同，则改为2019
        System.out.println(atomicInteger.compareAndSet(5, 2019)+"\t current data:"+atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 1024)+"\t current data:"+atomicInteger.get());

        System.out.println(atomicInteger.getAndIncrement());
    }
}
